object ActivityRegistration extends App {
  // 定义学生类，封装报名所需信息
  case class Student(
                      major: String,                // 专业
                      programmingScore: Int,        // 编程课程成绩
                      codingHoursPerWeek: Int,      // 每周代码投入时间（小时）
                      disciplinaryRecord: Boolean,  // 是否有违纪记录（true为有）
                      artisticTalent: String,       // 文艺特长（"唱歌"/"跳舞"/"乐器"/"表演"/"无"）
                      rehearsalAttendance: Int,     // 每周排练次数
                      grade: String,                // 年级（"大一"/"大二"/"大三"/"大四"）
                      peScore: Int,                 // 体育课程成绩
                      hasSeriousDisease: Boolean,   // 是否有重大疾病（true为有）
                      physicalRequirementMet: Boolean // 是否满足田径项目体能要求
                    )

  // 审核学生可参与的活动，返回(可参与活动列表, 各活动不通过原因)
  def auditActivities(student: Student): (List[String], Map[String, String]) = {
    var eligibleActivities = List.empty[String]
    var ineligibleReasons = Map.empty[String, String]

    // 审核编程大赛
    if ((student.major.contains("计算机") || student.programmingScore >= 85) &&
      student.codingHoursPerWeek >= 10 &&
      !student.disciplinaryRecord) {
      eligibleActivities = eligibleActivities :+ "编程大赛"
    } else {
      val reason = new StringBuilder("不满足以下条件：")
      if (!(student.major.contains("计算机") || student.programmingScore >= 85))
        reason.append(" 计算机相关专业或编程成绩≥85；")
      if (student.codingHoursPerWeek < 10)
        reason.append(" 每周代码投入时间≥10小时；")
      if (student.disciplinaryRecord)
        reason.append(" 无违纪记录；")
      ineligibleReasons += ("编程大赛" -> reason.toString())
    }

    // 审核文艺汇演
    if (List("唱歌", "跳舞", "乐器", "表演").contains(student.artisticTalent) &&
      student.rehearsalAttendance >= 2 &&
      List("大一", "大二").contains(student.grade)) {
      eligibleActivities = eligibleActivities :+ "文艺汇演"
    } else {
      val reason = new StringBuilder("不满足以下条件：")
      if (!List("唱歌", "跳舞", "乐器", "表演").contains(student.artisticTalent))
        reason.append(" 有文艺特长（唱歌/跳舞/乐器/表演）；")
      if (student.rehearsalAttendance < 2)
        reason.append(" 能参加每周2次排练；")
      if (!List("大一", "大二").contains(student.grade))
        reason.append(" 大一或大二学生；")
      ineligibleReasons += ("文艺汇演" -> reason.toString())
    }

    // 审核田径运动会
    if (student.peScore >= 80 &&
      !student.hasSeriousDisease &&
      student.physicalRequirementMet) {
      eligibleActivities = eligibleActivities :+ "田径运动会"
    } else {
      val reason = new StringBuilder("不满足以下条件：")
      if (student.peScore < 80)
        reason.append(" 体育课程成绩≥80；")
      if (student.hasSeriousDisease)
        reason.append(" 无重大疾病史；")
      if (!student.physicalRequirementMet)
        reason.append(" 满足对应项目的体能要求；")
      ineligibleReasons += ("田径运动会" -> reason.toString())
    }

    (eligibleActivities, ineligibleReasons)
  }

  // 测试用例：5种不同情况的学生
  val students = List(
    Student(
      major = "计算机科学",
      programmingScore = 90,
      codingHoursPerWeek = 15,
      disciplinaryRecord = false,
      artisticTalent = "无",
      rehearsalAttendance = 0,
      grade = "大一",
      peScore = 75,
      hasSeriousDisease = false,
      physicalRequirementMet = false
    ),
    Student(
      major = "中文",
      programmingScore = 80,
      codingHoursPerWeek = 8,
      disciplinaryRecord = false,
      artisticTalent = "唱歌",
      rehearsalAttendance = 3,
      grade = "大二",
      peScore = 85,
      hasSeriousDisease = false,
      physicalRequirementMet = true
    ),
    Student(
      major = "机械工程",
      programmingScore = 88,
      codingHoursPerWeek = 12,
      disciplinaryRecord = false,
      artisticTalent = "无",
      rehearsalAttendance = 0,
      grade = "大三",
      peScore = 90,
      hasSeriousDisease = false,
      physicalRequirementMet = true
    ),
    Student(
      major = "音乐",
      programmingScore = 60,
      codingHoursPerWeek = 5,
      disciplinaryRecord = true,
      artisticTalent = "乐器",
      rehearsalAttendance = 2,
      grade = "大一",
      peScore = 70,
      hasSeriousDisease = true,
      physicalRequirementMet = false
    ),
    Student(
      major = "体育教育",
      programmingScore = 75,
      codingHoursPerWeek = 10,
      disciplinaryRecord = false,
      artisticTalent = "表演",
      rehearsalAttendance = 4,
      grade = "大二",
      peScore = 82,
      hasSeriousDisease = false,
      physicalRequirementMet = true
    )
  )

  // 执行测试并输出结果
  for ((student, index) <- students.zipWithIndex) {
    val (eligible, ineligible) = auditActivities(student)
    println(s"=== 学生${index + 1} 审核结果 ===")
    println(s"可参与活动：${if (eligible.nonEmpty) eligible.mkString(", ") else "无"}")
    println("不符合活动及原因：")
    ineligible.foreach { case (activity, reason) =>
      println(s"  $activity：$reason")
    }
    println("=" * 30)
  }
}